package cn.rkylin.oms.base.brand.dao;

import cn.rkylin.oms.base.brand.domain.Brand;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.github.pagehelper.PageInfo;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.base.brand.vo.BrandVO;

/**
 * 类名：BrandDAOImpl<br>
 * 作用：品牌信息数据层<br>
 * 创建时间：2018年1月24日 下午2:39:23
 *
 * @author LiPeng
 */
@Repository
public class BrandDAOImpl implements IBrandDAO {

    @Autowired
    protected IDataBaseFactory dao;

    private static final String STATEMENT_PAGE_SELECT_BY_CONDITION = "pageSelectBrand";

    /**
     * queryBrandList:查询品牌信息列表
     */
    @Override
    public PageInfo<BrandVO> queryBrandList(int page, int length, BrandVO queryParamVO) throws Exception {
        return dao.findPage(page, length, STATEMENT_PAGE_SELECT_BY_CONDITION, queryParamVO);
    }

    @Override
    public int updateByMdmCodeSelectiveBrand(BrandVO brandVO) throws Exception {
        return dao.update("updateByMdmCodeSelectiveBrand", brandVO);
    }

    @Override
    public int insertSelectiveBrand(BrandVO brandVO) throws Exception {
        return dao.insert("insertSelectiveBrand", brandVO);
    }

    @Override
    public BrandVO selectByMdmCodeBrand(String mdmCode) throws Exception {
        return (BrandVO) dao.findOne("selectByMdmCodeBrand", mdmCode);
    }
    
    @Override
    public BrandVO selectByBrandCode(BrandVO brandVO) throws Exception {
        return (BrandVO) dao.findOne("selectByBrandCode", brandVO);
    }
    
    /**
     * 获取信息
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public BrandVO findById(String id) throws Exception {
        List<BrandVO> resultList = dao.findList("selectByPrimaryKeyBrandId", id);
        if (resultList != null && resultList.size() > 0) {
            return resultList.get(0);
        }
        return null;
    }

    /**
     * 创建怕品牌信息
     * @param brand
     * @return
     * @throws Exception
     */
	public int insert(Brand brand) throws Exception {
		return dao.insert("insertSelectiveBrand", brand);
	}
	
	/**
     * 修改品牌信息
     * @param brand
     * @return
     * @throws Exception
     */
	public int update(Brand brand) throws Exception {
		return dao.update("updateByBrandIdSelectiveBrand", brand);
	}
	
	/**
     * 删除品牌信息
     * @param id
     * @return
     * @throws Exception
     */
	@Override
    public int delete(String id) throws Exception {
        return dao.delete("deleteByPrimaryKeyBrandId", id);
    }
}
